草庐IT

python - 模块未找到错误 : No module named \'redis\'

全部标签

ruby-on-rails - 错误 "' Validate_default_type !': An option' s default must match its type (ArgumentError)"when running Ruby on Rails generate on Windows

我正在关注thistutorial并且刚刚开始。我已经使用geminstallrails安装了RubyonRails,并使用railsnewblog创建了一个博客。教程现在说我需要运行railsgeneratecontrollerWelcomeindex,但是当我这样做时,我得到了这个错误:C:/Ruby22/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/parser/option.rb:130:in`validate_default_type!':Anoption'sdefaultmustmatchitstype.(ArgumentErr

ruby - (Ruby) 是否有一个函数可以轻松找到字符串中的第一个数字?

例如,如果我输入“ds.35bdg56”,该函数将返回35。是否有类似的预制函数,或者我是否需要遍历字符串,找到第一个数字并查看它有多长去然后返回那个? 最佳答案 >>'ds.35bdg56'[/\d+/]=>"35"或者,既然你确实要求了一个功能......$irb>>deffx;x[/\d+/]end=>nil>>f'ds.35bdg56'=>"35"你真的可以从中获得一些乐趣:>>classString;deffirstNumber;self[/\d+/];end;end=>nil>>'ds.35bdg56'.firstNum

ruby-on-rails - 无方法错误 : undefined method `safe_constantize'

我有一个简单的模型:classPost它有一个名为type的INT列当我创建记录时:Post.create(:type=>1)我得到:NoMethodError:undefinedmethod`safe_constantize'for1:Fixnum我做错了什么? 最佳答案 就像这样:在Fixnum上没有名为safe_constantize的方法。type用于SingleTableInheritance.您通常会在应用程序中将已知模型的字符串表示形式作为type值。参见railsguides

ruby - 我如何找到 ruby​​ 解释器?

在ruby​​脚本中,如何获取ruby​​解释器的路径?示例脚本:#!/path/to/rubyputs`#{RUBY_INTERPRETER_PATH}-e"puts'hi'"`#EOF其中RUBY_INTERPRETER_PATH是寻找/path/to/ruby的神秘方式。不过,这只是一个例子。我意识到在这种情况下我可以将/path/to/ruby复制到脚本中,但我不想那样做。无论#!行说什么,我都希望它“正确”工作。即使在windows下运行。再见! 最佳答案 现在(1.9+)你可以像这样使用内置方法(应该与Jruby等一起工

ruby-on-rails - 程序 'rails' 可以在以下包中找到 - 某些应用程序和 RVM 有问题吗?

我刚刚从github下载了一个应用程序代码,当我尝试运行命令railss时,出现了这个错误-Theprogram'rails'canbefoundinthefollowingpackages:*rails*ruby-railties-3.2此问题仅适用于此应用,有人可以告诉我如何解决此问题吗?我正在使用RVM 最佳答案 以防其他人遇到此问题,但上述方法不起作用。尝试运行:/bin/bash--login然后运行rvmuse2.0.0#orwhateveryourversionnumberis...

ruby-on-rails - 如何在 Rails 中使用 Rspec stub 错误引发?

我是Rails和Rspec的新手,我正在使用Rspec来测试这个包含异常处理的Controller方法:defsearch_movies_director@current_movie=Movie.find(params[:id])begin@movies=Movie.find_movies_director(params[:id])rescueMovie::NoDirectorErrorflash[:warning]="#{@current_movie}hasnodirectorinfo"redirect_tomovies_pathendend我不知道如何正确测试上述路径:在无效搜索后

ruby-on-rails - 切换到 Rails 4.1 时出现错误 - `method_missing':ActiveRecord::Base:Class (NoMethodError) 的未定义方法 `whitelist_attributes='

从Rails4.0切换到Rails4.1时出现此错误:activerecord-4.1.8/lib/active_record/dynamic_matchers.rb:26:in`method_missing':undefinedmethod`whitelist_attributes='forActiveRecord::Base:Class(NoMethodError)我没有在我的应用程序的任何地方使用attr_accessible或attr_protected所以我想知道为什么我有问题。当迁移到Rails4.0时,我已经安装了我的application.rb:配置/应用程序.rb:c

ruby - 有没有一种快速的方法可以在 Ruby 中找到缺失的结尾?

syntaxerror,unexpected$end,expectingkeyword_end我们都去过那里!假设更改了足够多的代码以至于快速浏览一下gitdiff或类似的东西并不能使它变得明显,是否有一种简单的方法可以找到丢失的end(除了切换到一种基于缩进的语言,如Python)?FWIW,我使用SublimeText2作为我的编辑器。 最佳答案 如果您使用的是Ruby1.9,请在运行您的ruby​​程序时尝试使用-w标志。#t.rbclassExampledefmeth1ifTime.now.hours>12puts"Afte

ruby - 获取名称错误 : `format' is not allowed as an instance variable name when testing instance variable with rspec

我有以下测试:let(:client){Descat::Client.new}describe'poblacio'doit'shouldsetformatcorrectly'doclient.poblacio('v1','json','dades')expect(client.instance_variable_get(:format)).toeq('json')endend我有以下正在测试的代码:moduleDescatclassClientBASE_URL='http://api.idescat.cat/'definitialize(attributes={})attributes

ruby - 尝试从 FTP 下载文件导致 "500 Illegal PORT command"错误

如果我在本地执行,一切正常:require'net/ftp'ftp=Net::FTP.new("myftpserver.com","username","password")ftp.getbinaryfile("/myfile.zip","localfile.zip")ftp.close如果我尝试在我使用的Linux服务器上执行它,结果是:/usr/local/lib/ruby/1.9.1/net/ftp.rb:273:in`getresp':500IllegalPORTcommand.(Net::FTPPermError)from/usr/local/lib/ruby/1.9.1/n